//
//  ChartManager.swift
//  Alamofire
//
//  Created by tucici on 2024/7/1.
//

import UIKit

///标准设计的屏幕宽度
public var basicWidth : CGFloat = 375.0
///标准设计的屏幕高度
public var basicHeight : CGFloat = 667.0
private let k_s_w = UIScreen.main.bounds.width / basicWidth
private let k_s_h = UIScreen.main.bounds.height / basicHeight
//MARK: - //根据标准设计的宽高，自动扩大/压缩比例的宽高的协议
/// 根据标准设计的宽高，自动扩大/压缩比例的宽高的协议
public protocol TCC_AutoSize_protocol{
    var k_w : CGFloat{ get}
    var k_h : CGFloat{ get}
    var k_size : CGSize{ get}
    var k_frame : CGRect{ get}
    var k_edgeInset : UIEdgeInsets{ get}
}
public extension TCC_AutoSize_protocol {
    var k_w : CGFloat{
        switch self{
        case is CGFloat:
            return k_s_w * (self as! CGFloat)
        case is Float:
            return k_s_w * CGFloat((self as! Float))
        case is Double:
            return k_s_w * CGFloat((self as! Double))
        case is Int,
            is Int8,
            is Int32,
            is Int64:
            return k_s_w * CGFloat(self as? Int ?? 0)
        default:
            return 0.0
        }
    }
    
    var k_h : CGFloat{
        switch self{
        case is CGFloat:
            return k_s_h * (self as! CGFloat)
        case is Float:
            return k_s_h * CGFloat((self as! Float))
        case is Double:
            return k_s_h * CGFloat((self as! Double))
        case is Int,
            is Int8,
            is Int32,
            is Int64:
            return k_s_h * CGFloat(self as? Int ?? 0)
        default:
            return 0.0
        }
    }
    
    var k_size : CGSize{
        switch self{
        case is CGSize:
            return CGSize(width: (self as! CGSize).width * k_s_w, height: (self as! CGSize).height * k_s_h)
        default:
            return .zero
        }
    }
    
    var k_frame : CGRect{
        switch self{
        case is CGRect:
            let rect = self as! CGRect
            return CGRect(x: rect.minX * k_s_w,
                          y: rect.minY * k_s_h,
                          width: rect.size.width * k_s_w,
                          height: rect.size.height * k_s_h)
        default:
            return .zero
        }
    }
    
    var k_edgeInset : UIEdgeInsets{
        switch self{
        case is UIEdgeInsets:
            let inset = self as! UIEdgeInsets
            return UIEdgeInsets(top: inset.top * k_s_h,
                                left: inset.left * k_s_w,
                                bottom: inset.bottom * k_s_h,
                                right: inset.right * k_s_w)
        default:
            return .zero
        }
    }
}

extension CGFloat : TCC_AutoSize_protocol{
}
extension Double : TCC_AutoSize_protocol{
}
extension Float : TCC_AutoSize_protocol{
}
extension Int : TCC_AutoSize_protocol{
}
extension Int8 : TCC_AutoSize_protocol{
}
extension Int32 : TCC_AutoSize_protocol{
}
extension Int64 : TCC_AutoSize_protocol{
}
